import { create } from 'zustand'
import type { RouterData } from '@/api/menu/getRouters'

export type RouterInfoMeta = {
  title?: string,
  link?: string,
  href?: string,
  meta?: RouterData['meta']
}

export type State = {
  currentMeta?: RouterInfoMeta['meta'],
  stack: RouterInfoMeta[],
  currentName: string,
}

type Action = {
  changeRoute: (item: RouterInfoMeta['meta'], stack: RouterInfoMeta[], name: string) => void
}

const useCurrentPage = create<State & Action>((set) => ({
  currentMeta: undefined,
  stack: [],
  currentName: '__index__',
  changeRoute (item, data, name) {
    set(() => ({currentMeta: item, stack: [...data], currentName: name}))
  },
}))


export default useCurrentPage